package com.haoma.controller;

import com.haoma.dto.TalkDto;
import com.haoma.result.Result;
import com.haoma.service.TalkService;
import com.haoma.vo.AllTalkVo;
import com.haoma.vo.TalkPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * Description:
 */
@RestController
@RequestMapping("/admin/talk")
public class TalkController {

    @Autowired
    private TalkService talkService;

    /**
     * 获取所有的说说详情
     *
     * @return
     */
    @GetMapping("/list/{status}")
    public Result getTalkList(@PathVariable Integer status) {
        List<AllTalkVo> allTalkVoList = talkService.getTalkList(status);
        return Result.success(allTalkVoList);
    }

    /**
     * 隐藏说说
     *
     * @param id
     * @return
     */
    @PutMapping("/conceal/{id}/{status}")
    public Result concealTalk(@PathVariable Integer id, @PathVariable Integer status) {
        talkService.concealTalk(id, status);
        return Result.success();
    }

    /**
     * 删除评论
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delcomment/{id}/{talkId}")
    public Result delComment(@PathVariable Integer id, @PathVariable Integer talkId) {
        talkService.delComment(id, talkId);
        return Result.success();
    }

    /**
     * 发布说说
     *
     * @param talkDto
     * @return
     */
    @PostMapping("/send")
    public Result sendTalk(@RequestBody TalkDto talkDto) {
        talkService.sendTalk(talkDto);
        return Result.success();
    }

    /**
     * 上传说说图片
     *
     * @param multipartFile
     * @return
     */
    @PostMapping("/talkUpload")
    public Result fileUpload(@RequestParam("file") MultipartFile multipartFile) {
        String fileUrl = talkService.fileUpload(multipartFile);
        return Result.success(fileUrl);
    }

    /**
     * 修改说说
     *
     * @return
     */
    @PutMapping("/update/{id}")
    public Result updateTalk(@PathVariable Integer id, @RequestBody TalkDto talkDto) {
        talkService.updateTalk(id, talkDto);
        return Result.success();
    }

    /**
     * 删除说说
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deltalk/{id}")
    public Result delTalk(@PathVariable Integer id) {
        talkService.delTalk(id);
        return Result.success();
    }


    /**
     * 查询用户
     *
     * @param page
     * @param limit
     * @param name
     * @return
     */
    @GetMapping("/users/{page}/{limit}")
    public Result pageLabelList(@PathVariable Long page, @PathVariable Long limit,
                                @RequestParam(value = "name", required = false) String name) {
        TalkPageVo talkPageVo = talkService.getUserList(page, limit, name);
        return Result.success(talkPageVo);
    }

    /**
     * 删除用户
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deluser/{id}")
    public Result delUser(@PathVariable Integer id) {
        talkService.delUser(id);
        return Result.success();
    }
}
